/*
 * Copyright (c) 2016, www.zm0618.com All Rights Reserved..
 */

package com.ibetter.mr.grade.medic.score;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Created by zhaojun on 2016/12/12.
 */
public class GradeScoreCounterMapper extends Mapper<LongWritable,Text,Text,DoubleWritable>{
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        if (value!=null){
            String valStr=value.toString();
            String[] kvStr= StringUtils.split(valStr,"\t");
            if (ArrayUtils.getLength(kvStr)>=2){
                Text userMedicKey=new Text(StringUtils.trim(kvStr[0]));
                DoubleWritable  scoreVal=new DoubleWritable(Double.parseDouble(StringUtils.trim(kvStr[1])));
                context.write(userMedicKey,scoreVal);
            }
        }
    }
}
